﻿using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;

namespace EasyXaf.FullTextSearch;

public class FullTextSearchViewController : ViewController
{
    private FilterController _filterController;

    protected override void OnActivated()
    {
        base.OnActivated();

        _filterController = Frame.GetController<FilterController>();
        if (_filterController != null)
        {
            _filterController.CreateCustomSearchCriteriaBuilder += FilterViewController_CreateCustomSearchCriteriaBuilder;
        }
    }

    protected override void OnDeactivated()
    {
        if (_filterController != null)
        {
            _filterController.CreateCustomSearchCriteriaBuilder -= FilterViewController_CreateCustomSearchCriteriaBuilder;
        }

        base.OnDeactivated();
    }

    private void FilterViewController_CreateCustomSearchCriteriaBuilder(object sender, CreateCustomSearchCriteriaBuilderEventArgs e)
    {
        e.SearchCriteriaBuilder = new FullTextSearchCriteriaBuilder(Application.Model);
    }
}
